<?php
require('PresentacionP.class.php');

$modo = (isset($_GET['modo'])) ? $_GET['modo']:0;
switch($modo){
    case 1: //Consultar Grid
        if(isset($_GET['modo']) == 1){
            $page           = $_POST['page'];
            $rp             = $_POST['rp'];
            $sortname       = $_POST['sortname'];
            $sortorder      = $_POST['sortorder'];
            $query          = $_POST['query'];
            $letter_pressed = isset($_POST['letter_pressed'])?$_POST['letter_pressed']:null;
            $qtype          = $_POST['qtype'];
            $obj            = new PresentacionP();
            $obj->consultar_grid($page, $rp, $sortname, $sortorder, $query, $letter_pressed, $qtype);
        }
        break;
    case 2: //Insertar
        if(isset($_POST['submit'])){
            $nombre     = htmlspecialchars(trim($_POST['nombre']));
            $unidad     = htmlspecialchars(trim($_POST['unidad']));
            $obj        = new PresentacionP();
            if ( $obj->insertar(array($nombre,$unidad)) == true){
                   echo 1;
            }else{
                   echo 0;
            } 
        }
        break;
    case 3: //Modificar
        if(isset($_POST['submit'])){
            $id = $_POST['id'];
            $array[0]   =   htmlspecialchars(trim($_POST['nombre']));
            $array[1]   =   (trim($_POST['unidad']));
            $obj        = new PresentacionP();
            if ( $obj->actualizar($array, $id) == true){
                   echo 1;
            }else{
                   echo 0;
            } 
        }        
        break;
    case 4://Eliminar
        if(isset($_POST['submit'])){
            $id = $_POST['id'];
            $obj    = new PresentacionP();
            if ( $obj->eliminar($id) == true){
                   echo 1;
            }else{
                   echo 0;
            } 
        }             
        break;
    default:
        echo "Debe seleccionar un modo: \n1. Consultar Grid\n2. Insertar\n3. Modificar\n4. Eliminar";
}

?>
